/*
 * Author: http://www.redwolf-soft.com
 * All Rights Reserved
 * 
 * 2013.11
 *   
 * */
package com.redwolfsoft.libshoppingserver.shoppingcenter;

import java.util.ArrayList;
import java.util.List;




import net.sf.json.JSONArray;
import net.sf.json.JSONObject;



public class ShoppingCenterShopInfo {
	public final static String TAG = "ShoppingCenterShopInfo";
	
	public String displayName = null;
	public int number = 0;
	public List<ShoppingCenterBrandInfo> brandInfoList=null;
	
	public ShoppingCenterShopInfo(String name, int num,List<ShoppingCenterBrandInfo> list )
	{
		this.displayName=name;
		this.number=num;
		brandInfoList = list;
	}

	public ShoppingCenterShopInfo(JSONObject obj)
	{
		if(obj==null)
		{
		//	Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {				
			displayName = obj.getString("displayName");
			number = obj.getInt("number");			
			JSONArray array1 = obj.getJSONArray("brandInfoList");
			if(array1!=null){
				brandInfoList = new ArrayList<ShoppingCenterBrandInfo>(array1.size());
				for(int i=0;i<array1.size();i++)
				{			
					JSONObject info = array1.getJSONObject(i);
					//Log.d(TAG,info.toString());
					brandInfoList.add(new ShoppingCenterBrandInfo(info));
				}
			}
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {			
			obj.put("displayName", displayName);
			obj.put("number", number);			
			JSONArray array1 = new JSONArray();
			for(int i=0;i<brandInfoList.size();i++)
			{
				array1.add(i,brandInfoList.get(i).toJsonObject());
			}
			obj.put("brandInfoList", array1);
		//	obj2.put(TAG, obj);
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}*/
		return obj;
		
	}
}
